<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns="http://www.w3.org/1999/html">
<head>
<meta charset="utf-8"/>
<title>劲松商城后台</title>
<div th:include="Admin/public/Common::head"></div>
	<script type="text/javascript">
		$(function (){
			$(".JopenMaskPanel").click(function (){
				var id=$(this).attr("gameid");
				$.ajax({
					url:"http://localhost:8080/admin/getgame",
					type:"POST",
					data:{id:id},
					success:function (data){

						$("#id").attr("value",data.id);
						$("#gamename").attr("value",data.gamename);
						$("#price").attr("value",data.price);
						$("#1").attr("selected","selected");
					}
				})
			})
			$(".xiajia").click(function (){
				var id=$(this).attr("gameid");
				var pn=$(this).attr("pn");
				swal({
					title: "确定下架?",
					text: "一旦下架商城就没有商品了哟",
					icon: "warning",
					buttons: ["我再想想┭┮﹏┭┮", "确定下架！"],
					dangerMode: true,
					showCancelButton: true,
				})
						.then((willDelete) => {
							if (willDelete) {
								$.ajax({
									url:"http://localhost:8080/admin/xiajia",
									type:"POST",
									data: {gameid:id},
									success:function (data){
										swal("此商品已经下架", {icon: "success",}).then(function (){
											location.href="http://localhost:8080/admin/games?pn="+pn;
										});
									}
								})
							} else {
								swal("想好了再点哟");
							}
						});
			})
			$(".shangjia").click(function (){
				var id=$(this).attr("gameid");
				var pn=$(this).attr("pn");
				swal({
					title: "确定上架?",
					text: "一旦上架商城就有商品了哟",
					icon: "warning",
					buttons: ["我再想想┭┮﹏┭┮", "确定上架！"],
					dangerMode: true,
					showCancelButton: true,
				})
						.then((willDelete) => {
							if (willDelete) {
								$.ajax({
									url:"http://localhost:8080/admin/xiajia",
									type:"POST",
									data: {gameid:id},
									success:function (data){
										swal("此商品已经上架", {icon: "success",}).then(function (){
											location.href="http://localhost:8080/admin/games?pn="+pn;
										});
									}
								})
							} else {
								swal("想好了再点哟");
							}
						});
			})
			$("#check_all").click(function(){
				//attr获取checked是undefined;
				//我们这些dom原生的属性；attr获取自定义属性的值；
				//prop修改和读取dom原生属性的值
				$(".check_item").prop("checked",$(this).prop("checked"));
			});
		})
	</script>
</head>
<body>
<div class="main-wrap">
	<div th:include="Admin/public/Common::menu"></div>
	<div class="content-wrap">
<div th:replace="Admin/public/Common::header"></div>
		<main class="main-cont content mCustomScrollbar">
			<div class="page-wrap">
				<!--开始::内容-->
				<section class="page-hd">
					<header>

						<h2 class="title"><i class="fa  fa-gamepad ">&nbsp;</i>游戏管理</h2>
					</header>
					<hr>
				</section>
				<table class="table table-bordered table-striped table-hover">
					<thead>
						<tr>
							全选
							<th>
								<input type="checkbox" id="check_all"/>
							</th>
							<th>id</th>
							<th>游戏名称</th>
							<th>游戏平台</th>
							<th>访问量</th>
							<th>价格</th>
							<th>状态</th>
							<th>操作</th>
						</tr>
					</thead>
					<tbody>
						<tr class="cen" th:each="games:${pages.list}">
							<td><input type='checkbox' class='check_item'/></td>
							<td th:text="${games.id}"></td>
							<td><a href="#" th:text="${games.gamename}" style="color: #2E9EFE"></a></td>
							<td th:text="${games.platform}"></td>
							<td th:text="${games.viewcount}"></td>
							<td th:text="'￥'+${games.price}"></td>
							<td th:text="${games.status}==1?'上架中':'未上架'"></td>
							<td>
								<button class="btn btn-info-outline radius size-l JopenMaskPanel mr-10" th:gameid="${games.id}">编辑</button>
								<button th:if="${games.status}==1" class="btn btn-info-outline radius size-l xiajia" th:gameid="${games.id}" th:pn="${pages.pageNum}">下架</button>
								<button th:if="${games.status}==0"class="btn btn-danger-outline radius size-xl shangjia" th:gameid="${games.id}" th:pn="${pages.pageNum}">上架</button>
							</td>
						</tr>
					</tbody>
				</table>
				<!--开始::结束-->
				<center>
				<ul class="pagination justify-content-center">
					<li class="page-item"><a href="#" th:href="@{/admin/games(pn=${pages.getPrePage()})}">上一页</a></li>
					<li class="page-item" th:each="num:${pages.getNavigatepageNums()}">
						<a th:if="${num==pages.getPageNum()}" href="#" th:text="${num}"
						   th:href="@{/admin/games(pn=${num})}" style="color: blue"></a>
						<a th:if="${num!=pages.getPageNum()}" href="#" th:text="${num}"
						   th:href="@{/admin/games(pn=${num})}"></a>
					</li>
					<li class="page-item"><a href="#" th:href="@{/admin/games(pn=${pages.getNextPage()})}">下一页</a></li><br>
				</ul>
					<p th:text="当前+${pages.getPageNum()}+页+','+总共+${pages.getPages()}+页+','+总+${pages.getTotal()}+条记录"></p>
				</center>
			</div>
		</main>
		<div class="mask"></div>
		<div class="dialog">
			<form th:action="@{/admin/updategames}" method="post">
				<input type="hidden" name="id" value="" id="id"/>
				<input type="hidden" name="pn" th:value="${pages.pageNum}" id="pn"/>
			<div class="dialog-hd">
				<strong class="lt-title">编辑</strong>
				<a class="rt-operate icon-remove JclosePanel" title="关闭"></a>
			</div>
			<div class="dialog-bd">
				<div class="form-group-col-2">
					<div class="form-label">游戏名称：</div>
					<div class="form-cont">
						<input type="text" class="form-control form-boxed" value="" id="gamename" name="gamename">
					</div>
				</div>
				<div class="form-group-col-2">
					<div class="form-label">价格：</div>
					<div class="form-cont">
						<input type="text" class="form-control form-boxed" value="" id="price" name="price">
					</div>
				</div>
				<div class="form-group-col-2">
					<div class="form-label">游戏平台</div>
					<div class="form-cont">
						<select style="width:auto;" name="platform" id="platform">
							<option>选择平台</option>
							<option id="1">pc/xbox/ps4</option>
							<option id="2">pc/xbox</option>
							<option id="3">pc/ps4</option>
							<option id="4">xbox/ps4</option>
						</select>
					</div>
				</div>
			</div>
			<div class="dialog-ft">
				<button class="btn btn-info JyesBtn" type="submit">确认</button>
				<button class="btn btn-secondary JnoBtn" type="button">关闭</button>
			</div>
			</form>
		</div>
		<div th:replace="Admin/public/Common::footer"></div>
	</div>
</div>
</body>
</html>
